package cn.com.dhcc.ddi.datamapping.controller;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.com.dhcc.app.core.base.BaseController;
import cn.com.dhcc.app.core.exception.ServiceException;
import cn.com.dhcc.app.core.handler.modulehandler.WhereCondition;
import cn.com.dhcc.app.core.handler.pagerhandler.Pager;
import cn.com.dhcc.app.core.handler.pagerhandler.PagerData;
import cn.com.dhcc.app.core.service.Log;
import cn.com.dhcc.app.core.service.Log.LOGTYPE;
import cn.com.dhcc.app.core.util.StrUtil;
import cn.com.dhcc.ddi.datamapping.service.FuncIdentityService;
import cn.com.dhcc.ddi.datamapping.vo.FuncIdentify;

/**
 * 
 * @ClassName: DataIdentityController
 * @Description: 函数管理
 * @author fxx
 * @date 2016-12-14
 * 
 */
@Controller
@RequestMapping(value="/func_identify")
public class FuncIdentityController extends BaseController {
	private static Logger logger = Log.getLogger(LOGTYPE.DDI);
	@Autowired
	FuncIdentityService funcIdentityService;
	
	/**
	 * 
	 * @Title: list
	 * @Description: 函数管理列表
	 * @param @param model
	 * @param @param pager
	 * @param @param fxNameCn
	 * @param @return 参数
	 * @return String 返回类型
	 * @throws
	 */
	@RequestMapping(value="/func_identify_list")
	public String list(Model model, Pager pager, String fxNameCn){
		try {
			WhereCondition searchParameter = new WhereCondition();
			searchParameter.where1Eq1();
			if (StrUtil.isNotBank(fxNameCn)) {
				searchParameter.and().like("t1.fx_name_cn", "%"+fxNameCn+"%");
			}
			PagerData<FuncIdentify> datas = funcIdentityService.getPagerList(pager, searchParameter);
			model.addAttribute(DATA_KEY, datas.getDatas());
			setTotoal(model, datas.getTotal());
		} catch (ServiceException e) {
			logger.error("获取函数信息列表失败", e);
			return toAlertPage(model, "获取函数信息列表失败");
		}
		
		return "datamapping/func_identify_list";
	}		
	
	/**
	 * 
	 * @Title: list
	 * @Description: 查看函数信息
	 * @param @param model
	 * @param @param id
	 * @param @return 参数
	 * @return String 返回类型
	 * @throws
	 */
	@RequestMapping(value="/func_identify_get", method = RequestMethod.GET)
	public String list(Model model, String id){
		try {
			FuncIdentify vo = funcIdentityService.getById(id);
			model.addAttribute(VO_KEY, vo);
		} catch (ServiceException e) {
			logger.error("获取函数对象失败", e);
			return toAlertPage(model, "获取函数对象失败");
		}
		
		return "datamapping/func_identify_get";
	}


}
